package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    /**
     * 上报地理位置
     *  请求连接：location
     *  请求方式：post
     *  请求参数：
     *      latitude：维度，longitude：精度，addrStr：地理位置的中文描述
     */
    @PostMapping("/location")
    public ResponseEntity location(@RequestBody Map map) {
        String addrStr = (String) map.get("addrStr");
        Double latitude = (Double) map.get("latitude");
        Double longitude = (Double) map.get("longitude");
        baiduService.updateLocation(addrStr,latitude,longitude);
        return ResponseEntity.ok(null);
    }
}
